
<template>
	<view class="index-contain ">
		<scroll-view scroll-y="true"  @scrolltolower="toButtom">
			<!-- 搜索栏 -->
			<search></search>
			<!-- 轮播图 -->
			<IndexSwiper></IndexSwiper>
			<!-- 火爆推荐 -->
			<view class="HotRecommend">
				<view class="RecommendTitle">火爆推荐</view>
				<hot :bookList = "bookList"></hot>
			</view>
			<!-- 经典完本 -->
			<view class="EndRecommend">
				<view class="RecommendTitle">经典完本</view>
				<end :bookList = "bookList"></end>
			</view>
			<!-- 口碑新书 -->
			<view class="NewRecommend">
				<view class="RecommendTitle">口碑新书</view>
				<n :bookList="bookList"></n>
			</view>
		</scroll-view>
	</view>


</template>
<script>
	import end from '../../components/FinishRecommend/FinishRecommend.vue'
	import n from '../../components/NewRecommend/NewRecommend.vue'
	import hot from '../../components/HotRecommend/HotRecommend.vue'
	export default {
		components:{
			hot,
			end,
			n
		},
		data() {
			return {
				bookList:[],
			}
		},
		onLoad(){
			var that = this;
			setTimeout(function () {
				// that.getIndexData();
				console.log('start pulldown');
			}, 1000);
			uni.startPullDownRefresh();
			let userinfo = uni.getStorageSync('username');
			let account = uni.getStorageSync('account');
			let password = uni.getStorageSync('password');
			//判断是否存在登录信息
			if(!userinfo){
				console.log("----")
				uni.redirectTo({
					url:"../login/login"
				});
			}
      if(!account){
      	console.log("----")
      	uni.redirectTo({
      		url:"../login/login"
      	});
      }
      if(!password){
      	console.log("----")
      	uni.redirectTo({
      		url:"../login/login"
      	});
      }
      
      
		},
		onPullDownRefresh() {
			console.log('refresh');
			console.log(uni.getStorageSync('username'))

			let userinfo = uni.getStorageSync('username');
			let account = uni.getStorageSync('account');
			let password = uni.getStorageSync('password');
			//判断是否存在登录信息
			if(!userinfo){
				console.log("----")
				uni.redirectTo({
					url:"../login/login"
				});
			}
			if(!account){
				console.log("----")
				uni.redirectTo({
					url:"../login/login"
				});
			}
			if(!password){
				console.log("----")
				uni.redirectTo({
					url:"../login/login"
				});
			}

			var that = this;
			setTimeout(function () {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		created() {
			this.getIndexData();
		},
		methods:{
			getIndexData:function(){
				uni.request({
					url:'http://z7jxxt5.nat.ipyingshe.com/select/recommend',
					method:'POST',
					data:{
					},
					success:(res)=>{
							this.bookList = res.data.recommend;
						}
				});
			},
			toButtom(){

			}
		},

}
</script>

<style lang="scss">
	.index-contain{
		.RecommendTitle{
			border-left: thick solid #DD524D;
			border-left-width: 4px;
			height: 20px;
			margin:0 0 15px 5vw;
			padding-left: 5px;
			font-size: 17px;
		}
		.HotRecommend{
			width: 100vw;
			height: 59vh;
			margin-top: 3vh;
			margin-bottom: 6vh;
		}
		.EndRecommend{
			width: 100vw;
			height: 59vh;
			margin-bottom: 6vh;
		}
		.NewRecommend{
			width: 100vw;
			height: 59vh;
		}


	}

</style>
